#ifndef SHORTCUTLINEEDIT_H
#define SHORTCUTLINEEDIT_H

#include <QObject>
#include <QLineEdit>
#include <QKeyEvent>
#include <QKeySequence>
#include <QGSettings>
#include <QDebug>
#include <QPainter>
#include <QList>
#include <KGlobalAccel>
#include <KStandardShortcut>
#include "global/global.h"
#include "utils/confighandler.h"

class ShortcutLineEdit : public QLineEdit
{
    Q_OBJECT
public:
    explicit ShortcutLineEdit(const ShortcutRec &id, QWidget *parent = nullptr);
    ShortcutRec m_id;  // 标识符
    QString currentText = "";
    void onTextChanged(const QString &newText);//设置快捷键

signals:
    void shortcutChanged(ShortcutRec id, QString text);
protected:
    void keyPressEvent(QKeyEvent *event) override ;
    void focusOutEvent(QFocusEvent *event) override;
    void paintEvent(QPaintEvent *event) override;
private:

    bool isAvailableShortcut(QString shortcut);
    bool conflictWithGlobalShortcuts(const QKeySequence &keySequence);
    bool conflictWithStandardShortcuts(const QKeySequence &seq);
    QString keyToLib(QString key);

    int KeyStatus = 0;        //0 无效的 1 有效的 2 冲突的
    bool isAvailable = true;    //快捷键有效
    QString text = tr("热键冲突");
    QString preShortcut = "";
    QString mediakeys = "";

};

#endif // SHORTCUTLINEEDIT_H
